<?php

namespace App\Library\BearyChat;

use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;

class BearyChatJob implements ShouldQueue
{
    use InteractsWithQueue;
    use Queueable;
    use SerializesModels;

    /** @var \ElfSundae\BearyChat\Message */
    protected $message;

    public function __construct($message = null)
    {
        $this->message = $message;
    }

    public function handle()
    {
        if (is_null($this->message->getClient()->getWebhook())) {
            return;
        }

        try {
            $this->message->send();
        } catch (\Throwable $e) {
            // do nothing
        }
    }
}
